package com.xcesys.extras.remoting;

import java.util.Collection;
import java.util.List;

import com.xcesys.extras.core.dao.model.TreeEntity;
import com.xcesys.extras.core.service.ICrudService;
import com.xcesys.extras.core.service.ITreeCrudService;
import com.xcesys.extras.dataobject.TreeNode;

public abstract class BaseRemotingTreeCrudServiceImpl<D extends TreeNode<D>, M extends TreeEntity<M>>
		extends BaseRemotingServiceCrudImpl<D, M> implements
		RemotingTreeCrudService<D> {

	@Override
	public List<D> findByParentId(Long parentId) {
		return (List<D>) fromModel(getTreeCrudService()
				.findByParentId(parentId));
	}

	@Override
	public List<D> findAllChildrenByParentId(Long parentId) {
		return (List<D>) fromModel(getTreeCrudService()
				.findAllChildrenByParentId(parentId));
	}

	@Override
	public List<D> findSibling(D obj) {
		return (List<D>) fromModel(getTreeCrudService().findSibling(
				fromDataObject(obj)));
	}

	@Override
	public Integer findSiblingMaxSeq(D obj) {
		return getTreeCrudService().findSiblingMaxSeq(fromDataObject(obj));
	}

	@Override
	protected ICrudService<M> getCrudService() {
		return getTreeCrudService();
	}

	protected abstract ITreeCrudService<M> getTreeCrudService();

	@Override
	public Collection<D> moveDown(D obj) {
		return fromModel(getTreeCrudService().moveDown(obj.getId()));
	}

	@Override
	public Collection<D> moveUp(D obj) {
		return fromModel(getTreeCrudService().moveUp(obj.getId()));

	}

}
